<?php
/*
 * @分销商城
 * @功能说明：退货地址管理
 * @更新说明：暂无更新
 * @文件名 ReaddresController.class.php
 * @编码 UTF-8
 * @创建时间 2016-5-4 下午13:03:21
 * @创建人 BIE
 */
namespace dg\Controller;
use Think\Controller;
class ReaddresController extends ApibaseController {
	/*
	 * 分销商城_退货地址列表
	 * @date: 2016-5-4 下午13:03:21
	 * @editor: BIE
	 */
	public function index(){
		$list = M('ConfigSet');
		$getData = $list->where(array('config_column'=>'refundAddress'))->getField('config_val');
		$data = array();
		if($getData){
			$arr = explode('#',$getData);
			foreach($arr as $key=>$vo){
				$data[] = explode('|',$vo);	
			}
		}
		$this->assign('data',$data);
		$this->display('readdres/index');
	}
	  
	  
	 /*
	 * 分销商城_退货地址添加
	 * @date: 2016-5-4 下午13:03:21
	 * @editor: BIE
	 */
	  
	public function addset(){
	    $data=array();
		if(I('post.dosubmit')){
			$data['receiver'] = I('post.receiver');
			$data['phone'] = I('post.phone');
			$data['address'] = I('post.address');
			$len =count($data['receiver']);
			$res=array();
			for($i=0;$i<$len;$i++){
				$res[] = $data['receiver'][$i].'|'.$data['phone'][$i].'|'.$data['address'][$i];
			}
			$conf_val = implode('#',$res);
			$ares = M('ConfigSet')->where(array('config_column'=>'refundAddress'))->field('config_val')->find();
			if($ares['config_val']){
				$data= $ares['config_val'].'#'.$conf_val;
			}else{
				$data=$conf_val;
			}
		    $res = M('ConfigSet')->where(array('config_column'=>'refundAddress'))->setField(array('config_val'=>$data));
		    if($res){
			    $this->showtips('添加成功');
			}else{
				$this->showtips('操作失败');  
			} 
		}
		$this->display('readdres/addset');
	  }
	  
	/*
	 * 分销商城_退货地址修改
	 * @date: 2016-5-5 上午10:03:10
	 * @editor: BIE
	 */
	  
	public function addedit(){
		if(I('post.dosubmit')){
		    $getData =M('ConfigSet')->where(array('config_column'=>'refundAddress'))->getField('config_val');
		    $arr = explode('#',$getData);
			$arr[I('post.id')] = I('post.receiver').'|'.I('post.phone').'|'.I('post.address');
			$conf_val = implode('#',$arr);
			$result= M('ConfigSet')->where(array('config_column'=>'refundAddress'))->save(array('config_val'=>$conf_val));
			if($result){
			    $this->showtips('修改成功');
			}else{
				$this->showtips('操作失败'); 
			}
		}
		$id = I('get.id');
		$getData =M('ConfigSet')->where(array('config_column'=>'refundAddress'))->getField('config_val');
		$arr = explode('#',$getData);
		$datas = array();
		foreach($arr as $key=>$vo){
			$datas[] = explode('|',$vo);	
		}
		$data = $datas[$id];
		$this->assign('id',$id);
		$this->assign('data',$data);
		$this->display('readdres/addedit');  
	  }
	  
    /*
	 * 分销商城_退货地址删除
	 * @date: 2016-5-5 上午11:10:21
	 * @editor: BIE
	 */
	public function delete(){
    	$id = I('get.id');
		$getData =M('ConfigSet')->where(array('config_column'=>'refundAddress'))->getField('config_val');
		$arr = explode('#',$getData);
	    unset($arr[$id]);
		$conf_val = implode('#',$arr);
		$result= M('ConfigSet')->where(array('config_column'=>'refundAddress'))->save(array('config_val'=>$conf_val));
		if($result){
		    $this->showtips('删除成功');
		}else{
			$this->showtips('操作失败'); 
		}	
	}
		
    
}